package com.xu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @author anan
 * @create 2022-01-14 20:22
 */
@Configuration
public class CorsConfig {
    public CorsConfig() {
    }

    @Bean
    public CorsFilter corsFilter(){
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedOrigin("http://localhost:8080");
        config.addAllowedOrigin("http://shop.peiqili.top:8080");
        config.addAllowedOrigin("http://shop.peiqili.top");
        config.addAllowedOrigin("http://center.peiqili.top:8080");
        config.addAllowedOrigin("http://center.peiqili.top");
        config.addAllowedOrigin("*");

        config.addAllowedOrigin("http://124.222.194.185");
        config.setAllowCredentials(true);
        config.addAllowedMethod("*");
        config.addAllowedHeader("*");
        UrlBasedCorsConfigurationSource urlSource = new UrlBasedCorsConfigurationSource();
        urlSource.registerCorsConfiguration("/**", config);
        return new CorsFilter(urlSource);
    }
}